package com.ptc.ims.client.presenter;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Widget;
import com.ptc.ims.client.InventoryServiceAsync;
import com.ptc.ims.client.util.CustomDialogBox;

public abstract class AbstractPresenter 
extends Composite 
{
	private final InventoryServiceAsync inventoryService;
	private final HandlerManager handlerManager;	
	
	public AbstractPresenter(InventoryServiceAsync inventoryService, HandlerManager handlerManager) 
	{		
		this.inventoryService = inventoryService;
		this.handlerManager = handlerManager;	
	}

	public InventoryServiceAsync getInventoryService() 
	{
		return inventoryService;
	}
	
	public void go(HasWidgets container)
	{
		bind();
		container.clear();
		container.add(getView().asWidget());
	}
	
	public HandlerManager getHandlerManager() 
	{
		return handlerManager;
	}
	
	public CustomDialogBox createSimpleDialog(String buttonLabel, String title, String message)
	{
		final CustomDialogBox dialogBox = new CustomDialogBox();
		dialogBox.addButton(buttonLabel, new ClickHandler() {						
			@Override
			public void onClick(ClickEvent event) 
			{							
				dialogBox.hide();
			}
		});		
		return dialogBox.addTitle(title).addMessage(message).build();
	}
		
	public abstract void bind();
	public abstract DisplayView getView();
	
	public interface DisplayView
	{
		Widget asWidget();
	}	
}
